﻿// Copyright Microsoft

using System;
using System.IO;
using System.Data.SqlClient;
using Microsoft.Samples.SqlServer.Activities.Designers;

namespace Microsoft.Samples.SqlServer.Activities
{
  public static class Common
  { 
    public static SqlConnectionStringBuilder SqlConnectionBuilder
      (string dataSource, string initialCatalog, string userName, string password, bool hosted)
    {
      SqlConnectionStringBuilder connStringBuilder;
      connStringBuilder = new SqlConnectionStringBuilder();
      connStringBuilder.DataSource = dataSource;
      connStringBuilder.InitialCatalog = initialCatalog;

      if (hosted)
      {
        //SQLAzure
        connStringBuilder.Encrypt = true;
        connStringBuilder.TrustServerCertificate = false;
      }
           
      //This Version: Gets UserId and Password from LoginActivity.Credentials
      connStringBuilder.UserID = userName;
      connStringBuilder.Password = password;

      return connStringBuilder;
    }

    public static SqlConnectionStringBuilder SqlConnectionBuilder(string dataSource)
    {
      SqlConnectionStringBuilder connStringBuilder;
      connStringBuilder = new SqlConnectionStringBuilder();
      connStringBuilder.DataSource = dataSource;

      //Local Test
      connStringBuilder.IntegratedSecurity = true;
    
      return connStringBuilder;
    }
  }
}
